<script type="text/javascript">
	$(document).ready(function(){
		$('#content_more').click(function(){
			$('#content_more_detail').toggle();
		});
		$('#content_sort').click(function(){
			$('#content_sort_detail').toggle();
		});
		
		$('#check_all').click(function(){
			$(this).parent().find(':checkbox').attr('checked', this.checked);
			$("input[type=checkbox]").each(function(){
				if(this.checked == true){
					$("input[type=checkbox]").attr('checked','checked');
				}else{
					$("input[type=checkbox]").attr('checked',false);
				}
			});
		});
		
		// Date picker
		$( "#date_from" ).datepicker();
		$( "#date_to" ).datepicker();
	});
	function sort_by(value)
	{
		var url = "<?=base_url().'index.php/admin/'.$module.'/sort/'?>"
		$.post(url,{value: value},function(data){
			$('#ajax_list_post').html(data);
		});
	}
	
	function change_status(id_post,status)
	{
		var url	= "<?=base_url().'index.php/admin/'.$module.'/update_status/'?>";
		
		$.post(url,{id:id_post,status:status},function(data){
			$('#ajax_status_'+id_post).html(data);
		});
	}
	function check_all(result)
	{
		$('.check_item_0').click(function(){
			$(this).find(':checkbox').attr('checked', this.checked);
		});
		/*if(document.getElementById('check_item_0')!=null){
			if(document.getElementById('check_all').checked ==true)
			{
				for(var i = 0; i < result; i++)
				{
					itemCheck = document.getElementById('check_item_'+i);
					itemCheck.checked = true;
				}
			}else{
				for(var i = 0; i < result; i++)
				{
					itemCheck = document.getElementById('check_item_'+i);
					itemCheck.checked = false;
				}
			}
		}else{
			return false;
		}*/
	}
	function check_item(i)
	{
		item = document.getElementById('check_item_'+i);
		if(item.checked = true)
		{
			item.checked = false;
		}else{
			item.checked = true;
		}
	}
	
	function del_all(){
		/*var max = <?=count($result)?>
		for(var i = 0;i < max;i++)
		{
			if(document.getElementById('check_item_'+i).checked==true){
			id = $('#check_item_'+i).val();
			var url = '<?=PATH_URL.'admincp/'.$module.'/delete'?>';
			$.post(url,{
					id: id
				},
				function(data){
					searchContent();
				}
			);
		}*/
		var del = confirm("Bạn có chắc chắn xóa không?");
		if(del){
			$('#del_all_item').submit();
		}
	}
	
	function show_all()
	{
		var show = confirm("Bạn có chắc chắn hiện toàn bộ?");
		if(show)
		{
			if(document.getElementById('check_item_0')!=null){
				max = <?=count($result)?>;
				for(var i=0;i<max;i++){
					if(document.getElementById('check_item_'+i).checked==true){
						change_status($('#check_item_'+i).val(),0);
					}
					document.getElementById('check_item_'+i).checked=false;
				}
				document.getElementById('check_all').checked=false;
			}else{
				return false;
			}
		}
	}
	function hide_all()
	{
		var hide = confirm("Bạn có chắc chắn ẩn toàn bộ?");
		if(hide)
		{
			if(document.getElementById('check_item_0')!=null){
				max = <?=count($result)?>;
				for(var i=0;i<max;i++){
					if(document.getElementById('check_item_'+i).checked==true){
						change_status($('#check_item_'+i).val(),1);
					}
					document.getElementById('check_item_'+i).checked=false;
				}
				document.getElementById('check_all').checked=false;
			}else{
				return false;
			}
		}
	}
</script>
<div class="content_search">
	<div class="content_module"><?=ucfirst($module)?></div>
	<div class="content_button">
		<form action="<?=base_url().'index.php/admin/'.$module.'/search/'?>" method="POST" name="search" id="search">
		<div class="search_content">
			<input type="text" class="search_content_input" name="keyword" id="keyword"/>
		</div>
		<div class="search_content">
			<input type="text" class="date_from_content_input" name="date_from" id="date_from"/>
		</div>
		<div class="search_content">
			<input type="text" class="date_to_content_input" name="date_to" id="date_to"/>
		</div>
		<div class="left">
			<input class="content_button_detail" type="submit" name="submit" value="Search" />
		</div>
		<div style="float:left;position:relative;">
			<div class="content_button_detail left" id="content_more" style="position:relative;">
				<div style="float:left;">More</div>
				<div style="float:left;"><img src="<?=base_url().'static/images/arrow_down.png'?>" alt="" style="padding-top:15px;padding-left:5px;"/></div>
			</div>
			<div class="clearall"></div>
			<div style="display:none;position:absolute;z-index:100;top:30px;" class="content_more" id="content_more_detail">
				<div>
					<div class="more_line">Chuyên mục</div>
					<div class="more_line">Bán chạy</div>
					<div class="more_line">Khuyến mãi</div>
					<div class="no_more_line">Nodata</div>
				</div>
			</div>
		</div>
		<div class="clearall"></div>
		</form>
	</div>
</div>
<div class="content_navigation">
	<div class="content_post_title" style="width:670px;">
		<div class="content_change_language">
			<div id="content_sort" class="content_button_detail left" style="position:relative;">
				<div style="float:left;">Sort</div>
				<div style="float:left;"><img src="<?=base_url().'static/images/arrow_down.png'?>" alt="" style="padding-top:15px;padding-left:5px;"/></div>
				<div class="clearall"></div>
			</div>
			<div class="clearall"></div>
			<div id="content_sort_detail" class="content_wrap_sort left content_more" style="display:none;position:absolute;z-index:10;top:139px;">
				<div class="more_line" onclick="return sort_by(1)">Newest</div>
				<div class="more_line" onclick="return sort_by(2)">Oldest</div>
				<div class="more_line" onclick="return sort_by(5)">Order DESC</div>
				<div class="more_line" onclick="return sort_by(6)">Order ASC</div>
				<div class="more_line" onclick="return sort_by(3)">Active</div>
				<div class="no_more_line" onclick="return sort_by(4)">Unactive</div>
			</div> 
		</div>
	</div>
	<div class="content_post_action" style="width: 194px;">
		<div class="content_button_detail_search mr16 left" onclick="show_all()" title="Hiện toàn bộ">
			<div class="content_search_active">&nbsp;</div>
		</div>
		<div class="content_button_detail_search mr16 left" onclick="hide_all()" title="Ẩn toàn bộ">
			<div class="content_search_active">&nbsp;</div>
		</div>
		<div class="content_button_detail_search left" onclick="del_all()" title="Xóa toàn bộ">
			<div class="content_search_del">&nbsp;</div>
		</div>
		<div class="clearall"></div>
	</div>
	<div class="clearall"></div>
</div>
<div class="content_main_box">
	<div class="content_list_post" id="ajax_list_post">
	<?php $this->load->view("BACKEND/ajax_index");?>
	</div>
</div>